package com.example.myproject.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.myproject.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT * FROM user WHERE passkey = #{passkey} LIMIT 1")
    User findByPasskey(@Param("passkey") String passkey);

    @Select("SELECT user_name FROM user WHERE user_id = #{userId}")
    String selectUserNameById(Long userId);
    @Update("UPDATE user SET user_status = 'banned' WHERE user_id = #{userId}")
    void banUser(Long userId);

    @Update("UPDATE user SET user_status = #{status} WHERE user_id = #{userId}")
    void updateUserStatus(@Param("userId") Long userId, @Param("status") String status);

    @Select("SELECT user_id, user_name, user_level, role, user_status, created_time FROM user")
    List<User> selectAllUsersForAdmin();

    @Update("UPDATE user SET user_level = #{level} WHERE user_id = #{userId}")
    void updateUserLevel(@Param("userId") Long userId, @Param("level") Integer level);
}
